import { createRouter, createWebHistory } from 'vue-router';
import HomeView from '../views/HomeView/HomeView.vue';
import Author from '@/views/Author.vue';

const paths = import.meta.glob('../views/document/pages/**/Document.vue');
const children = Object.keys(paths).map((path) => {
    const list = path.split('/').reverse();
    return {
        path: list[2] + '/' + list[1],
        name: list[2] + '.' + list[1],
        component: paths[path]!,
    };
});

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            redirect: { name: 'home' },
        },
        {
            path: '/home',
            name: 'home',
            component: HomeView,
        },
        {
            path: '/author',
            name: 'author',
            component: Author,
        },
        {
            path: '/document',
            name: 'document',
            redirect: { name: children[0]!.name },
            component: () => import('../views/document/Document.vue'),
            children,
        },
    ],
});

export default router;
